<template>
	<view class="main">
		<view class="list_div">
			<view class="top">
				<image class="item_img" :src="dataList.avatar" mode=""></image>
				<view class="userInfo">
					<span>用户名：{{ dataList.name }}</span>
					<view class="time">
						<span>工龄：</span>
						{{ dataList.year }}
					</view>
				</view>
			</view>
			<view class="reservationInfo">
				<p>
					<span>预约日期：</span>
					{{ dataList.day }}
				</p>
				<p>
					<span>预约时间：</span>
					{{ dataList.time }}
				</p>
				<p>
					<span>服务内容：</span>
					{{ dataList.server_content }}
				</p>
				<p>
					<span>预留电话：</span>
					{{ dataList.mobile }}
				</p>
				<p>
					<span>上门地址：</span>
					{{ dataList.address }}
				</p>
			</view>
		</view>
		<view class="btn btn_com" @click="comHandle">完成</view>
		<view class="btn btn_can" @click="cancelHandle">取消</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			dataList: {}
		};
	},
	onLoad(option) {
		this.getData(option.id);
	},
	mounted() {},
	methods: {
		// 完成订单
		async comHandle() {
			// this.$wanlshop.to(`/pages/user/record/evaluate?id=${this.dataList.id}`);
			let data = {
				id: this.dataList.id
			};
			console.log(data);
			// return;
			await uni.request({
				url: '/worker/success_yao',
				method: 'POST',
				data,
				success: (res) => {
					if (res.code == 200) {
						this.$wanlshop.msg(res.msg || '请求成功！');
						this.$wanlshop.to(`/pages/user/record/evaluate?id=${this.dataList.id}`);
					} else {
						this.$wanlshop.msg(res.msg || '请求失败！');
					}
				}
			});
		},
		// 取消预约
		async cancelHandle() {
			// this.$wanlshop.to(`/pages/user/record/reservation`);
			let data = {
				id: this.dataList.id
			};
			console.log(data);
			// return;
			await uni.request({
				url: '/worker/cancel_yu',
				method: 'POST',
				data,
				success: (res) => {
					if (res.code == 200) {
						this.$wanlshop.msg(res.msg || '取消成功！');
						this.$wanlshop.to(`/pages/user/record/reservation`);
					} else {
						this.$wanlshop.msg(res.msg || '请求失败！');
					}
				}
			});
		},
		// 详情数据
		async getData(id) {
			let data = {
				id
			};
			console.log(data);
			// return;
			await uni.request({
				url: 'https://wanhuo.bigchun.com/index.php/api/worker/get_yu_info',
				method: 'POST',
				data,
				success: (res) => {
					console.log(res);
					if (res.res.code == 1) {
						this.dataList = res.res.data;
					} else {
						this.$wanlshop.msg(res.msg || '请求失败！');
					}
				}
			});
		}
	}
};
</script>

<style scoped lang="less">
.main {
	padding: 20rpx 34rpx;

	.list_div {
		height: 524rpx;
		padding: 24rpx 24rpx 40rpx;
		background-color: #fff;
		border-radius: 24rpx;
		display: flex;
		flex-direction: column;

		.top {
			display: flex;
			margin-bottom: 30rpx;

			.item_img {
				border-radius: 10rpx;
				width: 144rpx;
				height: 144rpx;
				margin-right: 24rpx;
			}

			.userInfo {
				span {
					font-size: 30rpx;
				}

				.time {
					font-size: 28rpx;

					span {
						color: #999999;
					}
				}
			}
		}

		.reservationInfo {
			flex: 1;
			display: flex;
			flex-direction: column;
			justify-content: space-between;

			p {
				span {
					color: #999999;
				}
			}
		}
	}

	.btn {
		width: 100%;
		height: 88rpx;
		text-align: center;
		line-height: 88rpx;
		border-radius: 44rpx;
	}

	.btn_com {
		margin-top: 40rpx;
		background-color: #fe6601;
		color: #fff;
	}

	.btn_can {
		margin-top: 20rpx;
		background-color: #e5e5e5;
		color: #9a9a9a;
	}
}
</style>
